from .utils import *
# 用于解析评论数据
import json
# 用于将上一级的上一级目录导入到当前文件夹
import sys
sys.path.append('..')
from word_cloud import *

# 获取评论词云图文件地址及搜索表单的关键字所匹配的第一个电影名称
def getCommentsImage(searchIpt):
    # 获取提交的搜索表单的关键字所匹配的第一个电影名称
    searchName = list(df[df['title'].str.contains(searchIpt)]['title'])[0]
    # 获取与searchName相对应的评论
    comments = df[df['title'] == searchName]['comments'].values[0]
    # 加载评论数据
    comments = json.loads(comments)
    resSrc = getImageByComments(comments)
    searchName = '《' + searchName + '》'

    return resSrc, searchName

# 获取电影名称词云图
def getTitleImage():
    titleImage = getImageByOthers('title', './static/img/title.png', './static/img/title_cloud.png')
    return titleImage

# 获取电影简介词云图
def getSummaryImage():
    summaryImage = getImageByOthers('summary', './static/img/summary.png', './static/img/summary_cloud.png')
    return summaryImage

# 获取演员名称词云图
def getCastsImage():
    castsImage = getImageByOthers('casts', './static/img/casts.png', './static/img/casts_cloud.png')
    return castsImage